//
//  ASSessionManager.h
//  AnisetteData
//
//  Created by 吴双 on 2023/1/23.
//

#import <Foundation/Foundation.h>
#import "ASType.h"

@class ASSessionManager, ASAccountSession, ALTAnisetteData;
@protocol ASSessionManagerAnisetteDataProvider;

typedef void(^ASVerifyResponse)(NSString *verifyCode);
typedef void(^ASVerifyRequest)(ASVerifyResponse verify);

@interface ASSessionManager : NSObject

/// On iOS, this value is required before login. You can use GlobalProvider (Maybe login failure) or extend new one (gen data by your service);
/// On macOS, if this value is nil, manager will fetch data from AltPlugin;
@property (nonatomic, strong) id<ASSessionManagerAnisetteDataProvider> anisetteDataProvider;

/// Call write to save after addCertificate, and call read on next fetch to match private key.
/// Default is storage in ~/.xauth/certificates
@property (nonatomic, strong) id<ASSessionManagerCertificateStorage> certificateStorage;

/// Logined sessions
@property (nonatomic, strong, readonly) NSArray<ASAccountSession *> *sessions;

/// Login Apple ID and get session token
/// - Parameters:
///   - AppleID: AppleID
///   - password: Password
///   - verify: Verify callback
///   - completion: Callback
- (void)login:(NSString *)AppleID
     password:(NSString *)password
       verify:(void (^)(void (^verify)(NSString *)))verify
    completed:(void (^)(ASAccountSession *accountSession, NSError *error))completion;

/// Logout Session
/// - Parameter session: ASAccountSession
- (void)logout:(ASAccountSession *)session;

@end
